package com.javase.data.structure.stack.array;

/**
 * 栈数组实现(业务实现)
 *
 * @author wangsh
 * @date 2018/11/18 17:36.
 */
public class StackArray {
    /**
     * 栈的大小
     */
    private int maxSize;
    private int top;
    /**
     * 栈：数组结构实现
     */
    private char[] arr;

    public StackArray(int size) {
        maxSize = size;
        top = -1;
        arr = new char[maxSize];
    }

    /**
     * 进栈
     *
     * @return
     */
    public void push(char value) {
        arr[++top] = value;
    }

    /**
     * 出栈
     *
     * @return
     */
    public char pop() {
        return arr[top--];
    }

    /**
     * 取栈顶元素
     *
     * @return
     */
    public char peek() {
        return arr[top];
    }

    /**
     * 是否满了
     *
     * @return
     */
    public boolean isFull() {
        return maxSize - 1 == top;
    }

    /**
     * 是否为空
     *
     * @return
     */
    public boolean isEmpty() {
        return top == -1;
    }
}
